<template>
  <div v-if="show" ref="mainContainer" class="top-container" @click="btnTop" >
    top
  </div>
</template>

<script>
  export default {
    data() {
      return {
        show: false,
      };
    },
    created() {
      this.$bus.$on("mainscroll",this.handleTop)
    },
    methods: {
      handleTop(dom){
        if(!dom){
          this.show = false;
          return 
        }
       this.show = dom.scrollTop >= 1000 ? true : false;
      },
      btnTop(){
        console.log(1);
        // 用事件总线改变detail 页面scrollTop值
        this.$bus.$emit("setMainScroll",0); // 触发事件
      }
    }
  }
</script>

<style lang="less" scoped>
.top-container{
  background: khaki;
  width: 50px;
  height: 50px;
  line-height: 50px;
  text-align:center;
  cursor: pointer;
  position: fixed;
  right: 50px;
  bottom: 50px;
  border-radius: 50%;
  // color:lighten(#fff,30%);
}
</style>